Skip to content

Claude/add minimizer filter method up8 al#670

Merged
alexander-akait merged 7 commits intomainfrom
claude/add-minimizer-filter-method-UP8AL
May 8, 2026
Merged

Claude/add minimizer filter method up8 al#670
alexander-akait merged 7 commits intomainfrom
claude/add-minimizer-filter-method-UP8AL

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

Summary

allow to use one instance of the plugin

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Already done

Use of AI

Claude

claude added 2 commits May 5, 2026 15:49
Each built-in minimizer now exposes a `filter(name, info)` helper based on
file extension. When `minify` is an array, each asset is dispatched only to
the minimizers whose `filter` accepts it; chain semantics still apply when
multiple minimizers claim the same asset. The `test` option defaults to
`undefined` for the array form so that filters can decide. This lets a
single `TerserPlugin` instance handle JS/CSS/HTML/JSON with one shared
worker pool instead of forcing a separate plugin instance per type.
`optimize()` was branching on whether the user passed a single minimizer
or an array, both for the gate ("does anything accept this asset?") and
for per-asset slicing. Normalize implementations and options to parallel
arrays once at the top of `optimize()` and reuse a single
`matchingMinimizers(name, info)` helper for both checks. Pass arrays to
`minify.js` unconditionally — it already normalizes a single function to
a one-element array internally.

Also extract the four extension regexes (JS/JSON/HTML/CSS) into shared
constants in `src/utils.js` so the 15 built-in `filter` helpers don't
each repeat the same literal.
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 5, 2026

CLA Not Signed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (1a34e62) to head (3cb4349).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #670      +/-   ##
==========================================
+ Coverage   95.87%   96.11%   +0.23%     
==========================================
  Files           3        3              
  Lines         558      592      +34     
  Branches      199      201       +2     
==========================================
+ Hits          535      569      +34     
  Misses         21       21              
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

claude added 5 commits May 5, 2026 16:59
…sset

Keep the original `test` default (`/\.[cm]?js(\?.*)?$/i`) for both single-
and array-of-minimizers form. Users who want to dispatch across asset
types in one plugin instance widen `test` themselves — the README example
now spells that out explicitly.

In `optimize()`, fold the gate and the per-asset record into a single
async pass: each asset returns either an empty array (skipped) or a
one-element array containing the record (with the matched-implementation
indices already computed). `Array.prototype.flat()` produces the final
list. The per-asset task reads `matched` directly from the record so the
filter regexes only run once per asset.
The per-asset shallow clone in `optimize()` only existed because
`minify.js` mutated `module`/`ecma` on the caller's options object, which
would have leaked across assets when a single options object was shared.
Move that overlay inside the `minify.js` loop and build it as a fresh
object via spread, so the same source options reference is safe to reuse.

`optimize()` no longer pre-expands a `minimizerOptionsList`: when the
configured options are an array, slice the matching subset (references,
not clones); otherwise pass the single object straight through. With a
shared options object and N minimizers across M assets that drops the
cloning from N×M to a single overlay per minimizer call.
`Array.prototype.flat` only landed in Node 11; the engines field is
`>= 10.13.0`. Restore the `.filter` + `.map` split and stash each
asset's matched-minimizer indices in a `Map` keyed by name, so the
matching regexes still run only once per asset and the array of
records is built without `flat`.
terser 5.47.1 was published after the previous lockfile update; the CI
test matrix on Node 10/12/14/16/18 uses `npm install` (which re-resolves
to the latest within `^5.31.1`) so it pulled 5.47.1, while Node 20+
ran `npm ci` and stayed on 5.46.2. The two terser versions mangle the
same input to slightly different identifiers, which left the committed
snapshots only valid for one half of the matrix.

Run `npm update terser` to align the lockfile with what the older-Node
install path resolves to, then `jest -u` to refresh the affected
snapshots in TerserPlugin/test-option/extractComments-option suites.
Drop the standalone `test/minimizer-filter.test.js` and re-express the
same coverage as snapshot tests in `test/minify-option.test.js`,
matching the surrounding style (real fixtures, `readsAssets` /
`getErrors` / `getWarnings` snapshots). The four new cases cover:

- a single TerserPlugin instance dispatching to terser + html-minifier
  via the array-of-minimizers form
- a single minimizer whose `filter` returns false (asset stays as-is)
- a single minimizer whose `filter` returns undefined (treated as accept)
- an array of minimizers whose filters all reject the asset
@alexander-akait alexander-akait merged commit 34610d9 into main May 8, 2026
28 of 29 checks passed
@alexander-akait alexander-akait deleted the claude/add-minimizer-filter-method-UP8AL branch May 8, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants